package src.test03;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;
import src.util.ConnectionUtil;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2023-08-21
 * Time: 21:48
 */
public class Task01 {
    public static final String QUEUE_NAME = "queue_ack";

    public static void main(String[] args) throws Exception{
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();
        channel.confirmSelect();
        //设置队列的持久化
        boolean durable = true;
        //申明一个队列
        channel.queueDeclare(QUEUE_NAME,durable, false, false,null);
        Scanner sc = new Scanner(System.in);
        while(true){
            String message = sc.next();
            channel.basicPublish("",QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN,message.getBytes());
            System.out.println("生产者发出消息");
        }
    }
}
